<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>结算</title>
<link rel="stylesheet" type="text/css" href="/style/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/swiper.min.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/xshop.css?ver=20180710"/>
<link rel="stylesheet" type="text/css" href="/style/css/sweet-alert.css"/>
<script src="/style/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/xShop.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/sweet-alert.min.js" type="text/javascript" charset="utf-8"></script>
<style>
input[type="checkbox"] {
text-indent:0;
margin: 0;
width: 17px;
height: 17px;
text-align:center;
display: inline-block;
vertical-align: middle;
line-height: 15px;
position: relative;
}
input[type="checkbox"]::before {
content: "";
position: absolute;
top: 0;
left: 0;
background: #fff;
width: 100%;
height: 100%;
border: 1px solid #bdbfc2;
}
input[type="checkbox"]:checked::before {
content: "\2713";
background-color: #f02c25;
color: #fff;
position: absolute;
top: 0;
left: 0;
width: 100%;
font-size: 12px;
font-weight: bold;
outline: none;
border-color:#ccc;
border: 1px solid #bdbfc2;
}
</style>
</head>
<body class="checkout">
<div class="outwrap">
	<div class="in-mian5 checkout">
		<div class="sh-info">
			<?php
if ($this->address) {
    ?>
			<div class="shmain clearfix">
				<a href="/cart/address?cartid=<?=$_GET['cartid'];?>">
					<h2 class="clearfix"><span class="name"><b><?=$this->address['realname'];?></b> <?=substr($this->address['mobile'], 0, 3) . '****' . substr($this->address['mobile'], 7, 4);?></span></h2>
					<p><?=$this->address['province_name'] . $this->address['city_name'] . $this->address['county_name'] . $this->address['address'];?></p>
				</a>
			</div>

			<?
} else {
    ?>
			<div class="add">
				<a href="/cart/address_add?cartid=<?=$_GET['cartid'];?>&back=checkout">添加收货地址&gt;&gt;</a>
			</div>
			<?
}
?>
			<div class="line"></div>
		</div>
		<?php
if ($this->data['cart'] && $this->data['goods']) {
    foreach ($this->data['cart'] as $cartid => $r) {
        if ($this->data['goods'][$r['goods_id']] && $r['stocknumber'] >= $r['number']) {
            $goods = $this->data['goods'][$r['goods_id']];
            $pic   = '/style/images/img22.jpg';

            if ($goods['thumb_docid'] > 0 && $this->data['docs'][$goods['thumb_docid']]) {
                $pic = $this->data['docs'][$goods['thumb_docid']];
            } elseif ($goods['pic_docid'] > 0 && $this->data['docs'][$goods['pic_docid']]) {
                $pic = $this->data['docs'][$goods['pic_docid']];
            }

            $total_number += $r['number'];
            
            ?>
		<div class="dingd-info">
			<dl class="clearfix">
				<dt><img src="<?=$pic;?>"/></dt>
				<dd>
					<h2 <?php if(!$r['word']):?> style="height: 1rem;" <?php endif;?>  ><?=stripslashes($goods['goods_name']);?><?= $r['attr_str']?></h2>
                    <p style="font-size:10px;"><?= $r['attr_str']?></p>
					<div style="color: red;margin-top:5px;"><?=$r['word']?></div>
					<span class="price"><b><?php
if ($r['shop_price'] > 0) {
                echo '￥' . $r['shop_price'];
            } elseif ($goods['ximi_price'] > 0) {
                echo ($goods['ximi_price'] * 1) . '硒米';
            }
            ?></b>
					<p><?php
if ($goods['price_me'] > 0 || $goods['coupon_price'] > 0) {
             /*   if ($goods['price_me'] > 0) {
                    echo '返' . ($goods['price_me'] * 1);
                }

                if ($goods['coupon_price'] > 0) {
                    echo ' 抵券' . $goods['coupon_price'];
                }*/
            }
            ?></p>
					</span>
					<span class="num">数量 <?=$r['number'];?></span></dd>
			</dl>
		</div>

		<?
        }
    }
}
?>

		<form method="post" action="saveorder" id="frm">
		 <div class="dingd-ot-info">
			<dl class="clearfix">
				<dt>运费</dt>
				<dd class="shipping_fee">
					<span><?=$this->shipping_fee > 0 ? '￥' . $this->shipping_fee : '免运费';?></span>
				</dd>
			</dl>

			<dl class="clearfix">
				<dt>优惠券</dt>
				<dd class="coupon"><select name="coupon_id" id="select_coupon">

					<?php
if ($this->coupon) {
    echo '<option value="">--选择优惠券--</option>';
    foreach ($this->coupon as $r) {

        if ($r['type'] == 1 && $this->shipping_fee > 0 && $this->is_free_shipping <= 0) {

            ?>
					<option value="<?=$r['coupon_id'];?>" data-money="<?=$r['money'];?>">免运费券 <?=date("Y-m-d", $r['expire_time']);?>到期</option>
					<?
        } elseif ($r['type'] == 2) {
            ?>
					<option<?=$this->total_price >= $r['need_money'] ? '' : ' disabled="disabled"';?>  value="<?=$r['coupon_id'];?>" data-money="<?=$r['money'];?>" data-needmoney="<?=$r['need_money'];?>">满<?=$r['need_money'];?>抵<?=($r['money'] * 1);?> <?=date("Y-m-d", $r['expire_time']);?>到期</option>
					<?
        }
    }
} else {
    echo '<option value="">暂无可用优惠券</option>';
}
?>
				</select></dd>
			</dl>

			<?php if ($this->balance['coupon'] > 0 && $this->coupon_total > 0) {
		    $dis_coupon_chk = 1;
		    ?>
			<dl class="clearfix">
				<dt>代金券抵扣</dt>
				<dd onclick="deduction('coupon');">
					<input type="checkbox" name="coupon" id="coupon" checked="checked" />
					<span style="padding-left: .2rem; color: #666;">允许抵扣：<?=$this->coupon_total;?></span>
					<span style="color:#666;float:right">可用数量：<?=$this->balance['coupon'];?></span>
				</dd>
			</dl>
            <?php }?>

			<?php if ($this->balance['gold_money'] > 0 && $this->gold_total > 0) {
		    $dis_gold_chk = 1;
		    ?>
			<dl class="clearfix">
				<dt>金花抵扣</dt>
				<dd onclick="deduction('gold_money');">
					<input type="checkbox" name="gold_money" id="gold_money" checked="checked" />
					<span style="padding-left: .2rem; color: #666;">允许抵扣：<?=$this->gold_total;?></span>
					<span style="color:#666;float:right">可用数量：<?=($this->balance['gold_money'] * 1)?></span>
				</dd>
			</dl>
			<?php }?>


			<dl class="clearfix">
				<dt>留言</dt>
				<dd><input type="text" class="txt" placeholder="选填，想要对我们的留言" name="remark"/></dd>
			</dl>

		</div>
		<input type="hidden" name="act" value="save">
		<input type="hidden" name="cartid" value="<?=$_GET['cartid'];?>">
		<input type="hidden" name="address_id" id="address_id" value="<?=$this->address['id'];?>">
		<input type="hidden" name="declaration" id="declaration" value="<?=$this->declaration;?>">
		<input type="hidden" name="dis_gold" value="<?=$dis_gold_chk ?: 0;?>" id="dis_gold">
		<input type="hidden" name="dis_coupon" value="<?=$dis_coupon_chk ?: 0;?>" id="dis_coupon">

		</form>
	</div>

	<!--底部导航-->
	<div class="foot-js">
		<div>
		<span class="gongjsp">共<b><?=$total_number;?></b>件商品<span class="tprice"><b>￥<?=$this->total_price;?></b></span> <span class="gongtxt"><?php
if ($this->total_price_ximi > 0) {
    echo $this->total_price_ximi . '硒米';
}
?></span></span>
        <a class="settle_btn" href="javascript:settle_btn();" id="btn-qrzf">确认支付</a>
    	</div>
	</div>

	<div class="blackbg"></div>
	<div class="tczf">
		<span class="close"></span>
		<h2>确认付款</h2>
		<h4><b id="talp">￥<?=$this->total_price;?></b></h4>
		<?php
if ($this->total_price_ximi > 0) {
    echo '<h4><b>' . $this->total_price_ximi . '硒米</b></h4>';
}
?>
		<ul>
			<li><i class="ico ico-1"><img src="/style/images/tb_wx.png"/></i><span>微信支付</span></li>
		</ul>
		<a href="javascript:_saveOrder();" class="btn-ljfk">立即付款</a>
	</div>
</div>

<script type="text/javascript">
var _total_price = <?=$this->total_price;?>,
_new_money = <?=$this->total_price;?>,
_coupon_total = <?=$this->coupon_total ?: 0;?>,
_coupon_max = <?=$this->balance['coupon'] ?: 0;?>,
_gold_total = <?=$this->gold_total ?: 0;?>,
_gold_max = <?=$this->balance['gold_money'] ?: 0;?>,
_ximi_max = <?=$this->balance['ximi_money'] ?: 0?>,
_ximi_price = <?=$this->total_price_ximi ?: 0;?>,
_oldcoupon = 0,
_shipping_fee = <?=$this->shipping_fee ?: 0;?>;
$(document).ready(function(e){

   $(".dingd-ot-info dl dd input").on("click",function(){
   	deduction( $(this).prop("name") );
   });

   $("#select_coupon").bind("change",function(){

    	_oldcoupon = 0;

    	if(	$(this).val()!="")
    	{
    		 _coupon_money = parseFloat( $("#select_coupon option:selected").attr("data-money") );
    		if(_coupon_money>0)
    		{
        		_oldcoupon = _coupon_money;

    		}
    	}

    	deduction('');

    });

   deduction('');
});

//抵扣计算
function deduction(id){

	if(id=="coupon")
	{
		if(! $("#coupon").prop("checked") )
		{
			$("#coupon").prop("checked","true");
			$("#dis_coupon").prop("value","1");
		}
		else
		{
			$("#dis_coupon").prop("value","0");
			$("#coupon").removeAttr("checked");
		}
	}

	if(id=="gold_money")
	{
		if(! $("#gold_money").prop("checked") )
		{
			$("#dis_gold").prop("value","1");
			$("#gold_money").prop("checked","true");
		}
		else
		{
			$("#dis_gold").prop("value","0");
			$("#gold_money").removeAttr("checked");
		}
	}

	var _dis_gold = true,_dis_coupon = true;

	if( !$("#coupon").prop("checked") )
	{
		_dis_coupon = false;
	}

	if(! $("#gold_money").prop("checked") )
	{
		_dis_gold = false;
	}


	_new_money = _total_price - _oldcoupon;


	if(_dis_gold && _gold_total>0)
	{
		if(_gold_max >= _gold_total)
		{
			_new_money -= _gold_total;
		}
		else
		{
			_new_money -= _gold_max;
		}
	}

	if(_dis_coupon && _coupon_total>0)
	{
		if(_coupon_max >= _coupon_total)
		{
			_new_money -= _coupon_total;
		}
		else
		{
			_new_money -= _coupon_max;
		}
	}

	if(_new_money<0)
	{
		_new_money = 0;
	}


    $(".tprice b").html('￥'+_new_money.toFixed(2));


 }
function settle_btn()
{
	var type=true;
	var addr ="<?=$this->address['idnum'];?>";
	var word_number = <?=$this->no_sale ? : 0?>;

	if(word_number>0)
	{
		swal("有商品当前收货地址不支持销售");

		type =  false;
	}

	if( $("#declaration").prop("value")==1)
	{
		if(addr  ==''){
		swal("收件人需要填写身份证号码");

		type =  false;
       }
	}


	if(type && _ximi_price > 0 && _ximi_max < _ximi_price)
	{
		type = false;
		swal("可用硒米不足，无法下单");
	}

	if(type){

		$(".tczf #talp").html('￥'+_new_money.toFixed(2));

		$(".tczf").show();
		$('.blackbg').show();

	}else{
		$('.blackbg').hide();
		$(".tczf").hide();
	}
}


var _act = false;
function _saveOrder()
{
	if(!_act)
	{
		if( $("#address_id").prop("value")=="")
		{
			swal("请选择收货人");
			return   false;
		}
		_act = true;
		$("#frm").submit();
	}

}

</script>

</body>
</html>
